import Vue from 'vue'
import Vuex from 'vuex'
import axios from "axios";

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    list: [],
    total: 0
  },
  mutations: { // vuex最终所有的数据。最终都提交给了mutation commit
    ['ALL_USER_DATA'](state, arr) {
      console.log(arr, '我是数控')
      state.list = arr.data;
      state.total = arr.data.total;
    }
  },
  actions: { // 异步请求数据的地方
    async getAllData({ commit }, params) {
      console.log(params, 'params')
      let data = await axios.get("http://localhost:3000/api/page", {
        params
      });
      console.log(data, "data");
      commit('ALL_USER_DATA', data)
    }
  },
  modules: {
  }
})
